home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / Unsupported Samples / CRC Cards / Source / UDesignDocument.inc1.p < prev    next >
Encoding:
Text File  |  1990-07-11  |  23.1 KB  |  919 lines  |  [TEXT/MPS ]

  1. (*******************************)
  2. (* methods for TDesignDocument *)
  3. (*******************************)
  4. {$S AOpen}
  5. PROCEDURE TDesignDocument.IDesignDocument;
  6.  
  7.     VAR
  8.         aList:    TList;
  9.         aTextHandler:TTextHandler;
  10.         
  11.     BEGIN
  12.         fCurrentCard:= NIL;
  13.         IDocument(kFileType, kSignature, kUsesDataFork, NOT kUsesRsrcFork, 
  14.                             NOT kDataOpen, NOT kRsrcOpen);
  15.         fSavePrintInfo:= TRUE;
  16.         
  17.         aList:= NewList;
  18.         fCardList:= aList;
  19.         
  20.         fDesignView:= NIL;
  21.         
  22.         SetUnitName('NotSetYet');
  23.         
  24.         SELF.SetMPWCodeView(NIL);
  25.         SELF.SetMPWIncCodeView(NIL);
  26.         
  27.         NEW(aTextHandler);
  28.         FailNil(aTextHandler);
  29.         aTextHandler.ITTextHandler(SELF);
  30.         SELF.SetTextHandler(aTextHandler);
  31.     END;   {TDesignDocument.IDesignDocument}
  32.  
  33. {$S ARes}
  34. PROCEDURE TDesignDocument.SetCurrentCard(theCard: TCard);
  35.  
  36.     VAR
  37.         theSimpleView: TSimpleVIew;
  38.         
  39.     BEGIN
  40.         IF fCurrentCard <> NIL THEN
  41.             BEGIN
  42.                 theSimpleView:= fCurrentCard.GetSimpleView;
  43.                 IF theSimpleView <> NIL THEN
  44.                     BEGIN
  45.                         theSimpleView.DoHighlightSelection(hlOn, hlOff);
  46.                         theSimpleView.SetSelected(NOT kIsSelected);
  47.                     END;
  48.             END;
  49.         fCurrentCard:= theCard;
  50.         IF theCard <> NIL THEN
  51.             BEGIN
  52.                 theSimpleView:= theCard.GetSimpleView;
  53.                 IF theSimpleView <> NIL THEN
  54.                     BEGIN
  55.                         theSimpleView.SetSelected(kIsSelected);
  56.                         theSimpleView.DoHighlightSelection(hlOff, hlOn);
  57.                     END;
  58.             END;
  59.     END;   {TDesignDocument.SetCurrentCard}
  60.  
  61. {$S ARes}
  62. FUNCTION TDesignDocument.GetCurrentCard: TCard;
  63.     BEGIN
  64.         GetCurrentCard:= fCurrentCard;
  65.     END;   {TDesignDocument.GetCurrentCard}
  66.  
  67. {$S ARes}
  68. PROCEDURE TDesignDocument.SetCardList(theCardList: TList);
  69.     BEGIN
  70.         fCardList:= theCardList;
  71.     END;   {TDesignDocument.SetCardList}
  72.  
  73. {$S ARes}
  74. FUNCTION TDesignDocument.GetCardList: TList;
  75.     BEGIN
  76.         GetCardList:= fCardList;
  77.     END;   {TDesignDocument.GetCardList}
  78.  
  79. {$S ARes}
  80. FUNCTION TDesignDocument.GetNumCardsStr: str255;
  81.  
  82.     VAR
  83.         numCards: ArrayIndex;
  84.         theString: str255;
  85.         
  86.     BEGIN
  87.         numCards:= SELF.GetNumCards;
  88.         NumToString(numCards + 1, theString);
  89.         GetNumCardsStr:= theString;
  90.     END;   {TDesignDocument.GetNumCardsStr}
  91.  
  92. {$S ARes}
  93. FUNCTION TDesignDocument.GetDesignView: TDesignView;
  94.     BEGIN
  95.         GetDesignView:= fDesignView;
  96.     END;    {TDesignDocument.GetDesignView}
  97.     
  98. {$S ARes}
  99. PROCEDURE TDesignDocument.SetDesignView(aDesignView: TDesignView);
  100.     BEGIN
  101.         fDesignView:= aDesignView;
  102.     END;    {TDesignDocument.SetDesignView}
  103.     
  104. {$S ARes}
  105. FUNCTION TDesignDocument.GetTextHandler: TTextHandler;
  106.     BEGIN
  107.         GetTextHandler:= fTextHandler;
  108.     END;    {TDesignDocument.GetTextHandler}
  109.     
  110. {$S ARes}
  111. PROCEDURE TDesignDocument.SetTextHandler(theTextHandler: TTextHandler);
  112.     BEGIN
  113.         fTextHandler:= theTextHandler;
  114.     END;    {TDesignDocument.SetTextHandler}
  115.     
  116. {$S ARes}
  117. FUNCTION TDesignDocument.GetMPWCodeView: TMyTEView;
  118.  
  119.     BEGIN
  120.         GetMPWCodeView:= fMPWCodeView;
  121.     END;    {TDesignDocument.GetMPWCodeView}
  122.     
  123. {$S ARes}
  124. PROCEDURE TDesignDocument.SetMPWCodeView(theMPWCodeView: TMyTEView);
  125.  
  126.     BEGIN
  127.         fMPWCodeView:= theMPWCodeView;
  128.     END;    {TDesignDocument.SetMPWCodeView}
  129.  
  130. {$S ARes}
  131. FUNCTION TDesignDocument.GetMPWIncCodeView: TMyTEView;
  132.  
  133.     BEGIN
  134.         GetMPWIncCodeView:= fMPWIncCodeView;
  135.     END;    {TDesignDocument.GetMPWIncCodeView}
  136.     
  137. {$S ARes}
  138. PROCEDURE TDesignDocument.SetMPWIncCodeView(theMPWIncCodeView: TMyTEView);
  139.  
  140.     BEGIN
  141.         fMPWIncCodeView:= theMPWIncCodeView;
  142.     END;    {TDesignDocument.SetMPWIncCodeView}
  143.  
  144. {$S ARes}
  145. FUNCTION TDesignDocument.GetUnitName:Str255;
  146.     BEGIN
  147.         GetUnitName:=fUnitName;
  148.     END; {TDesignDocument.GetUnitName}
  149.     
  150. {$S ARes}
  151. PROCEDURE TDesignDocument.SetUnitName(theUnitName: Str255); 
  152.     BEGIN
  153.         fUnitName:=theUnitName;
  154.     END; {TDesignDocument.SetUnitName}
  155.     
  156. {$S ARes}
  157. PROCEDURE TDesignDocument.SetTitle(aTitle: Str255); OVERRIDE;
  158.  
  159.     BEGIN
  160.         INHERITED SetTitle(aTitle);
  161.         SELF.SetUnitName(fTitle^^);
  162.     END;    {TDesignDocument.SetTitle}
  163.  
  164. {$S ADoCommand}
  165. PROCEDURE TDesignDocument.AddCard(aCard: TCard);
  166.         
  167.     BEGIN
  168.         fCardList.InsertLast(aCard);
  169.         IF fDesignView <> NIL THEN
  170.             aCard.CreateSimpleView(fDesignView, SELF);
  171.         SELF.SetCurrentCard(aCard);
  172.         SELF.AddCardToObjectLists(aCard);
  173.     END;   {TDesignDocument.AddCard}
  174.  
  175. {$S ADoCommand}
  176. PROCEDURE TDesignDocument.AddCardAtIndex(aCard: TCard; theIndex: ArrayIndex);
  177.         
  178.     BEGIN
  179.         IF theIndex <= fCardList.GetSize THEN
  180.             BEGIN
  181.                 fCardList.InsertBefore(theIndex, aCard);
  182.                 IF fDesignView <> NIL THEN
  183.                     aCard.CreateSimpleView(fDesignView, SELF);
  184.                 SELF.AddCardToObjectLists(aCard);
  185.             END
  186.         ELSE
  187.             SELF.AddCard(aCard);
  188.         SELF.SetCurrentCard(aCard);
  189.     END;   {TDesignDocument.AddCardAtIndex}
  190.  
  191. {$S ADoCommand}
  192. PROCEDURE TDesignDocument.AddCardToObjectLists(theCardToAdd: TCard);
  193.  
  194.     PROCEDURE AddTheClass(aCard: TCard);
  195.  
  196.     BEGIN
  197.         aCard.AddCardToObjectLists(theCardToAdd);
  198.     END;
  199.     
  200. BEGIN
  201.     SELF.GetCardList.Each(AddTheClass);
  202. END; {TDesignDocument.AddCardToObjectLists}
  203.  
  204. {$S ADoCommand}
  205. PROCEDURE TDesignDocument.RemoveCardFromObjectLists(theCardToRemove: TCard);
  206.  
  207.     PROCEDURE RemoveTheClass(aCard: TCard);
  208.  
  209.     BEGIN
  210.         aCard.RemoveCardFromObjectLists(theCardToRemove);
  211.     END;
  212.     
  213. BEGIN
  214.     SELF.GetCardList.Each(RemoveTheClass);
  215. END; {TDesignDocument.RemoveCardFromObjectLists}
  216.  
  217. {$S ADoCommand}
  218. PROCEDURE TDesignDocument.ChangeNameInObjectLists(theOldName, theNewName: Str255);
  219.  
  220.     PROCEDURE ChangeTheName(aCard: TCard);
  221.  
  222.     BEGIN
  223.         aCard.ChangeNameInObjectLists(theOldName, theNewName);
  224.     END;
  225.     
  226. BEGIN
  227.     SELF.GetCardList.Each(ChangeTheName);
  228. END; {TDesignDocument.ChangeNameInObjectLists}
  229.  
  230. {$S ADoCommand}
  231. PROCEDURE TDesignDocument.DeleteCard(aCard: TCard);
  232.         
  233.     BEGIN
  234.         fCardList.Delete(aCard);
  235.         SELF.SetCurrentCard(NIL);
  236.         aCard.DeleteSimpleView;
  237.         aCard.DeleteEditView;
  238.         fDesignView.ForceRedraw;
  239.         SELF.RemoveCardFromObjectLists(aCard);
  240.     END;   {TDesignDocument.DeleteCard}
  241.  
  242. {$S ARes}
  243. FUNCTION TDesignDocument.GetNumCards: ArrayIndex;
  244.  
  245.     BEGIN
  246.         GetNumCards:= fCardList.GetSize;
  247.     END;    {TDesignDocument.GetNumCards}
  248.  
  249. {$S ARes}
  250. FUNCTION TDesignDocument.GetIndexOfCard(theCard: TCard): ArrayIndex;
  251.  
  252.     BEGIN
  253.         IF theCard <> NIL THEN
  254.             GetIndexOfCard:= fCardList.GetEqualItemNo(theCard)
  255.         ELSE
  256.             GetIndexOfCard:= kCardNotFound;
  257.     END;    {TDesignDocument.GetIndexOfCard}
  258.     
  259. {$S AOpen}
  260. PROCEDURE TDesignDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
  261.  
  262.     VAR
  263.         aWindow:            TWindow;
  264.         aDesignView:    TDesignView;
  265.         aHandler:            TStdPrintHandler;
  266.         
  267.     PROCEDURE MakeSimpleViews(theCard: TCard);
  268.     
  269.         VAR
  270.             theSimpleView: TSimpleView;
  271.     
  272.         BEGIN
  273.             theCard.SetDesignView(aDesignView);
  274.             theCard.CreateSimpleView(fDesignView, SELF);
  275.             theSimpleView:= theCard.GetSimpleView;
  276.             theSimpleView.SetSelected(NOT kIsSelected);
  277.         END;    {MakeSimpleViews}
  278.         
  279.     BEGIN
  280.         aWindow := NewTemplateWindow(kDesignWindowID, SELF);
  281.         aDesignView := TDesignView(aWindow.FindSubView('dsgn'));
  282.         SELF.SetDesignView(aDesignView);
  283.         New(aHandler);
  284.         FailNIL(aHandler);
  285.         aHandler.IStdPrintHandler(SELF, aDesignView, NOT kSquareDots, kFixedSize, kFixedSize);
  286.         aHandler.InstallMargins(gZeroRect, kUseMinimalMargins);
  287.         
  288.         IF fCardList.GetSize > kNoCards THEN
  289.             BEGIN
  290.                 fCardList.Each(MakeSimpleViews);
  291.                 SELF.SetCurrentCard(SELF.GetCurrentCard);
  292.             END;
  293.     END;   {TDesignDocument.DoMakeViews}
  294.  
  295. {$S ARes}
  296. PROCEDURE TDesignDocument.CloseOldCodeViews;
  297.  
  298.     VAR
  299.         theMPWTextDoc: TMPWTextDocument;
  300.  
  301.     BEGIN
  302.         IF fMPWCodeView <> NIL THEN
  303.             BEGIN
  304.                 theMPWTextDoc:= TMPWTextDocument(fMPWCodeView.fDocument);
  305.                 theMPWTextDoc.Close;
  306.             END;
  307.         IF fMPWIncCodeView <> NIL THEN
  308.             BEGIN
  309.                 theMPWTextDoc:= TMPWTextDocument(fMPWIncCodeView.fDocument);
  310.                 theMPWTextDoc.Close;
  311.             END;
  312.     END;    {TDesignDocument.CloseOldCodeViews}
  313.  
  314. {$S ARes}
  315. PROCEDURE TDesignDocument.OpenNewCodeViews;
  316.  
  317.     VAR
  318.         anMPWIncCodeView: TMyTEView;
  319.         anMPWCodeView: TMyTEView;
  320.         anMPWInterfaceDocument: TMPWInterfaceDocument;
  321.         anMPWImplementationDocument: TMPWImplementationDocument;
  322.  
  323.     BEGIN
  324.         IF fMPWIncCodeView = NIL THEN
  325.             BEGIN
  326.                 NEW(anMPWImplementationDocument);
  327.                 FailNIL(anMPWImplementationDocument);
  328.                 anMPWImplementationDocument.IMPWImplementationDocument(SELF, 
  329.                                                                                     SELF.GetTextHandler,SELF.GetUnitName);
  330.                 anMPWImplementationDocument.DoMakeViews(kForPrinting);
  331.                 anMPWIncCodeView:= anMPWImplementationDocument.GetTEView;
  332.                 anMPWIncCodeView.SetDesignDoc(SELF);
  333.                 SELF.SetMPWIncCodeView(anMPWIncCodeView);
  334.             END;
  335.  
  336.         IF fMPWCodeView = NIL THEN
  337.             BEGIN
  338.                 NEW(anMPWInterfaceDocument);
  339.                 FailNIL(anMPWInterfaceDocument);
  340.                 anMPWInterfaceDocument.IMPWInterfaceDocument(SELF,
  341.                                                                                     SELF.GetTextHandler,SELF.GetUnitName);
  342.  
  343.                 anMPWInterfaceDocument.DoMakeViews(kForPrinting);
  344.                 anMPWCodeView:= anMPWInterfaceDocument.GetTEView;
  345.                 anMPWCodeView.SetDesignDoc(SELF);
  346.                 SELF.SetMPWCodeView(anMPWCodeView);
  347.             END;
  348.     END;    {TDesignDocument.OpenNewCodeViews}
  349.  
  350. {$S ARes}
  351. PROCEDURE TDesignDocument.SelectCurrentCodeViews;
  352.  
  353.     VAR
  354.         theWindow: TWindow;
  355.  
  356.     BEGIN
  357.         theWindow:= fMPWIncCodeView.GetWindow;
  358.         theWindow.Select;
  359.         theWindow:= fMPWCodeView.GetWindow;
  360.         theWindow.Select;
  361.     END;    {TDesignDocument.SelectCurrentCodeViews}
  362.  
  363. {$S ARes}
  364. PROCEDURE TDesignDocument.WriteInterface(theTEView: TMyTEView);
  365.  
  366.     PROCEDURE WriteTheCardInterfaces(theCard: TCard);
  367.     
  368.         BEGIN
  369.             theCard.WriteInterface(theTEView);
  370.         END;
  371.  
  372.     PROCEDURE WriteTheFwdClassDecl(theCard: TCard);
  373.     
  374.         BEGIN
  375.             theCard.WriteFwdClassDecl(theTEView);
  376.         END;
  377.  
  378.     BEGIN
  379.         theTEView.WriteToMyTEView(fTextHandler.GetHeadingStr);
  380.         IF SELF.GetNumCards > kNoCards THEN
  381.             BEGIN
  382.                 fCardList.Each(WriteTheFwdClassDecl);
  383.                 fCardList.Each(WriteTheCardInterfaces);
  384.             END;
  385.         theTEView.WriteToMyTEView(fTextHandler.GetImplementationStr);
  386.         theTEView.WriteToMyTEView(fTextHandler.GetIncludeStatement);
  387.         theTEView.WriteToMyTEView(fTextHandler.GetUnitEndStr);
  388.     END;    {TDesignDocument.WriteInterface}
  389.  
  390. {$S ARes}
  391. PROCEDURE TDesignDocument.WriteImplementation(theTEView: TMyTEView);
  392.  
  393.     PROCEDURE WriteTheCardImplementations(theCard: TCard);
  394.     
  395.         BEGIN
  396.             theCard.WriteImplementation(theTEView);
  397.         END;
  398.  
  399.     BEGIN
  400.         IF SELF.GetNumCards > kNoCards THEN
  401.             BEGIN
  402.                 theTEView.WriteToMyTEView(fTextHandler.GetImplIncFileStr);
  403.                 fCardList.Each(WriteTheCardImplementations);
  404.             END;
  405.     END;    {TDesignDocument.WriteImplementation}
  406.  
  407. {$S ARes}
  408. FUNCTION TDesignDocument.GetUnitNameFromUser;
  409.  
  410. CONST
  411.     kSelectChars = TRUE;
  412.     kUNameView = 'UNAM';
  413.     kUnit = 'Unme';
  414.     kmodalID = 1004;
  415.     
  416. VAR
  417.     aWindow:    TWindow;
  418.     aDialogView: TDialogView;
  419.     theTEName : TEditText;
  420.     dismisser : IDType;
  421.     theName : Str255;
  422.     
  423. BEGIN
  424.     aWindow := NewTemplateWindow(kmodalID, NIL);        
  425.     theTEName := TEditText(aWindow.FindSubView(kUnit));    
  426.     theName:=SELF.GetUnitName;
  427.     theTEName.SetText(theName,TRUE);    
  428.     aDialogView := TDialogView(aWindow.FindSubView(kUNameView));        
  429.     dismisser := aDialogView.PoseModally;        
  430.     IF dismisser = 'okok' THEN
  431.         BEGIN
  432.             GetUnitNameFromUser:=TRUE;
  433.             theTEName.GetText(theName);
  434.             SELF.SetUnitName(theName);
  435.         END;
  436.     IF dismisser = 'cncl' THEN
  437.         GetUnitNameFromUser:=FALSE;
  438.     aWindow.Close;        
  439. END; {TDesignDocument.GetUnitNameFromUser}
  440.  
  441. {$S ARes}
  442. PROCEDURE TDesignDocument.WriteCode;
  443.  
  444.     BEGIN
  445.     IF     (SELF.GetChangeCount > kNoChanges) OR
  446.             (fMPWCodeView = NIL) OR 
  447.             (fMPWIncCodeView = NIL) THEN
  448.         BEGIN
  449.             IF SELF.GetUnitNameFromUser THEN 
  450.                 BEGIN
  451.                     SELF.CloseOldCodeViews;
  452.                     SELF.OpenNewCodeViews;
  453.                     fMPWCodeView.ClearText;
  454.                     fMPWIncCodeView.ClearText;
  455.                     SELF.WriteInterface(fMPWCodeView);
  456.                     SELF.WriteImplementation(fMPWIncCodeView);
  457.                     fMPWCodeView.FinishWriteOperation;
  458.                     fMPWIncCodeView.FinishWriteOperation;
  459.                 END;
  460.         END
  461.     ELSE
  462.         SELF.SelectCurrentCodeViews;
  463.     END;    {TDesignDocument.WriteCode}
  464.  
  465. {$S AClose}
  466. PROCEDURE TDesignDocument.FreeData; OVERRIDE;
  467. VAR    
  468.     theCardList:TList;
  469.     
  470.     PROCEDURE DeleteTheCard(aCard: TCard);
  471.     BEGIN
  472.         SELF.DeleteCard(aCard);
  473.         aCard.Free;
  474.     END;
  475.     
  476. BEGIN
  477.     theCardList:=SELF.GetCardList;
  478.     theCardList.Each(DeleteTheCard);
  479.     INHERITED FreeData;
  480. END; {TDesignDocument.FreeData}
  481.  
  482. {$S AClose}
  483. PROCEDURE TDesignDocument.Free; OVERRIDE;
  484.     BEGIN
  485.         IF fMPWCodeView <> NIL THEN
  486.             fMPWCodeView.DesignDocumentIsGone;
  487.         IF fMPWIncCodeView <> NIL THEN
  488.             fMPWIncCodeView.DesignDocumentIsGone;
  489.         IF fCardList <> NIL THEN
  490.             fCardList.FreeList;
  491.         fTextHandler.Free;
  492.         INHERITED Free;
  493.     END;   {TDesignDocument.Free}
  494.  
  495. {$S AWriteFile}
  496. PROCEDURE TDesignDocument.DoNeedDiskSpace(
  497.                                 VAR dataForkBytes, rsrcForkBytes: LONGINT); OVERRIDE;
  498.     {
  499.         file format:
  500.             print info (done by MacApp and our INHERIRED call)
  501.             language
  502.             number of cards (ArrayIndex)
  503.             current item (ArrayIndex )
  504.             for each card:    (handled by the card objects)
  505.                 name of class
  506.                 name of super class
  507.                 number of fields (ArrayIndex)
  508.                 that many strings (str255)
  509.                 number of methods (ArrayIndex)
  510.                 that many strings (str255)
  511.                 number of collaborators (ArrayIndex)
  512.                 that many strings (str255)
  513.                 *** note ***     no accessors are stored, they are created 
  514.                                             during the read operation
  515.     }
  516.     
  517.     VAR
  518.         numCards: INTEGER;
  519.         language: INTEGER;
  520.         
  521.     PROCEDURE CalcOurBytes(theCard: TCard);
  522.     
  523.         BEGIN
  524.             dataForkBytes:= dataForkBytes + theCard.ReturnBytes;
  525.         END;    {CalcOurBytes}
  526.         
  527.     BEGIN
  528.         INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
  529.         dataForkBytes:= 0;
  530.         language:= fTextHandler.GetLanguage;
  531.         dataForkBytes:= dataForkBytes + SIZEOF(language);
  532.         numCards:= fCardList.GetSize;
  533.         dataForkBytes:= dataForkBytes + SIZEOF(numCards);    { there will at least be a zero }
  534.         dataForkBytes:= dataForkBytes + SIZEOF(ArrayIndex);    {for the current item number}
  535.         IF NumCards > 0 THEN
  536.             fCardList.Each(CalcOurBytes);
  537.     END;   {TDesignDocument.DoNeedDiskSpace}
  538.     
  539. {$S AWriteFile}
  540. PROCEDURE TDesignDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
  541.  
  542.     {
  543.         file format:
  544.             print info (done by MacApp and our INHERIRED call)
  545.             language
  546.             number of cards (ArrayIndex)
  547.             current item (ArrayIndex )
  548.             for each card:    (handled by the card objects)
  549.                 class name
  550.                 super class name
  551.                 number of fields (ArrayIndex)
  552.                 that many strings (str255)
  553.                 number of methods (ArrayIndex)
  554.                 that many strings (str255)
  555.                 number of collaborators (ArrayIndex)
  556.                 that many strings (str255)
  557.                 *** note ***     no accessors are stored, they are created 
  558.                                             during the read operation
  559.     }
  560.     
  561.     VAR
  562.         numCards,
  563.         currentCardNumber: ArrayIndex;
  564.         language: INTEGER;
  565.         dataBytes: LONGINT;
  566.     
  567.     PROCEDURE WriteACardInTheList(aCard: TCard);
  568.         BEGIN
  569.             aCard.WriteCard(aRefNum);
  570.         END;    {WriteACardInTheList}
  571.         
  572.     BEGIN
  573.         {first the print stuff from MacApp}
  574.         INHERITED DoWrite(aRefNum, makingCopy);
  575.         
  576.         {now the language}
  577.         language:= fTextHandler.GetLanguage;
  578.         dataBytes:= SIZEOF(language);
  579.         FailOSErr(FSWrite(aRefNum, dataBytes, @language));
  580.         
  581.         {now the number of cards in our document and the current item number}
  582.         numCards := fCardList.GetSize;
  583.         IF (numCards > kNoCards) AND (SELF.GetCurrentCard <> NIL) THEN
  584.             currentCardNumber:= fCardList.GetEqualItemNo(SELF.GetCurrentCard)
  585.         ELSE
  586.             currentCardNumber:= kNotFound;
  587.         dataBytes := SIZEOF(numCards);
  588.         FailOSErr(FSWrite(aRefNum, dataBytes, @numCards));
  589.         FailOSErr(FSWrite(aRefNum, dataBytes, @currentCardNumber));
  590.         
  591.         {write each card's data if there are any cards}
  592.         IF numCards > kNoCards THEN
  593.             fCardList.Each(WriteACardInTheList);
  594.     END;   {TDesignDocument.DoWrite}
  595.     
  596. {$S AReadFile}
  597. PROCEDURE TDesignDocument.DoRead(aRefNum: INTEGER; 
  598.                         rsrcExists, forPrinting: BOOLEAN); OVERRIDE;
  599.  
  600.     {
  601.         file format:
  602.             print info (done by MacApp and our INHERIRED call)
  603.             language
  604.             number of cards (ArrayIndex)
  605.             current item (ArrayIndex )
  606.             for each card:    (handled by the card objects)
  607.                 name of class
  608.                 name of super class
  609.                 number of fields (ArrayIndex)
  610.                 that many strings (str255)
  611.                 number of methods (ArrayIndex)
  612.                 that many strings (str255)
  613.                 number of collaborators (ArrayIndex)
  614.                 that many strings (str255)
  615.                 *** note ***     no accessors are stored, they are created 
  616.                                             during the read operation
  617.     }
  618.     
  619.     VAR
  620.         language:         INTEGER;
  621.         currentItemNum,
  622.         numCards:            ArrayIndex;
  623.         aCard:                TCard;
  624.         index:                ArrayIndex;
  625.         dataBytes:        LONGINT;
  626.     
  627.     BEGIN
  628.         INHERITED DoRead(aRefNum, rsrcExists, forPrinting);    {read printer info}
  629.         
  630.         SetUnitName(fTitle^^);
  631.         dataBytes:= SIZEOF(language);
  632.         FailOSErr(FSRead(aRefNum, dataBytes, @language));
  633.         fTextHandler.SetLanguage(language);
  634.         
  635.         dataBytes:= SIZEOF(ArrayIndex);
  636.         FailOSErr(FSRead(aRefNum, dataBytes, @numCards));
  637.         FailOSErr(FSRead(aRefNum, dataBytes, @currentItemNum));
  638.         
  639.         IF numCards > 0 THEN
  640.             BEGIN
  641.                 FOR index:= 1 to numCards DO
  642.                     BEGIN
  643.                         NEW(aCard);
  644.                         FailNil(aCard);
  645.                         aCard.ICard(SELF, gZeroVPt);
  646.                         aCard.ReadCard(aRefNum);
  647.                         SELF.AddCard(aCard);
  648.                         SELF.SetCurrentCard(NIL);
  649.                     END;
  650.                 
  651.                 IF currentItemNum = kNotFound THEN
  652.                     SELF.SetCurrentCard(NIL)
  653.                 ELSE
  654.                     BEGIN
  655.                         aCard:= TCard(fCardList.At(currentItemNum));
  656.                         SELF.SetCurrentCard(aCard);
  657.                     END;
  658.             END;
  659.     END;   {TDesignDocument.DoRead}
  660.  
  661. {$S ASelCommand}
  662. FUNCTION  TDesignDocument.DoMenuCommand(aCmdNumber: CmdNumber):TCommand;OVERRIDE;
  663.  
  664.     BEGIN
  665.         DoMenuCommand:= gNoChanges;
  666.         CASE aCmdNumber OF
  667.             cWriteCodeCmd:    SELF.WriteCode;
  668.             cInPascalCmd:    
  669.                 IF SELF.GetTextHandler.GetLanguage=kInCPP THEN
  670.                     BEGIN
  671.                         SELF.GetTextHandler.ChangeLanguageTo(kInPascal);
  672.                         SELF.SetChangeCount(SELF.GetChangeCount + 1);
  673.                     END;
  674.             cInCPPCmd:    
  675.                 IF SELF.GetTextHandler.GetLanguage=kInPascal THEN
  676.                     BEGIN
  677.                         SELF.GetTextHandler.ChangeLanguageTo(kInCPP);
  678.                         SELF.SetChangeCount(SELF.GetChangeCount + 1);
  679.                     END;
  680.             OTHERWISE                            {always do this, so other objects get a chance}
  681.                 DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  682.     
  683.             END;  {Case}
  684.     END;    {TDesignDocument.DoMenuCommand}
  685.     
  686.  
  687.     {$S ARes}
  688.     PROCEDURE TDesignDocument.DoSetupMenus; OVERRIDE;
  689.     
  690.     VAR
  691.         Index:Integer;
  692.         
  693.     BEGIN
  694.         INHERITED DoSetupMenus;
  695.         IF     SELF.GetNumCards > kNoCards THEN
  696.             Enable(cWriteCodeCmd, TRUE);
  697.         FOR Index:=1 TO kNumberOfLanguages DO
  698.             BEGIN
  699.                 Enable(Index + cInPascalCmd -1, TRUE);
  700.                 EnableCheck(Index + cInPascalCmd -1, TRUE, (Index=SELF.GetTextHandler.GetLanguage));
  701.             END;
  702.     END;    {TDesignDocument.DoSetupMenus}
  703.     
  704.     
  705. {$S AFields}
  706. PROCEDURE TDesignDocument.Fields(PROCEDURE DoToField(
  707.             fieldName: Str255; fieldAddr: Ptr; fieldType: INTEGER)); OVERRIDE;
  708.     BEGIN
  709.         DoToField('TDesignDocument', NIL, bClass);
  710.         DoToField('fCurrentCard', @fCurrentCard, bObject);
  711.         DoToField('fCardList', @fCardList, bObject);
  712.         DoToField('fDesignView', @fDesignView, bObject);
  713.         DoToField('fTextHandler', @fTextHandler, bObject);
  714.         DoToField('fUnitName', @fUnitName, bString);
  715.         DoToField('fMPWCodeView', @fMPWCodeView, bObject);
  716.         DoToField('fMPWIncCodeView', @fMPWIncCodeView, bObject);
  717.         INHERITED Fields(DoToField);
  718.     END;   {TDesignDocument.Fields}
  719.  
  720.  
  721. (********************************)
  722. (* methods for TMPWTextDocument *)
  723. (********************************)
  724.  
  725. {$S ARes}
  726. FUNCTION TMPWTextDocument.GetDocText: Handle;
  727.  
  728.     BEGIN
  729.         GetDocText:= fDocText;
  730.     END;    {TMPWTextDocument.GetDocText}
  731.  
  732. {$S ARes}
  733. PROCEDURE TMPWTextDocument.SetDocText(theHandle: Handle);
  734.  
  735.     BEGIN
  736.         fDocText:= theHandle;
  737.     END;    {TMPWTextDocument.SetDocText}
  738.  
  739. {$S ARes}
  740. FUNCTION TMPWTextDocument.GetTEView: TMyTEView;
  741.  
  742.     BEGIN
  743.         GetTEView:= fTEView;
  744.     END;    {TMPWTextDocument.GetTEView}
  745.  
  746. {$S ARes}
  747. PROCEDURE TMPWTextDocument.SetTEView(theTEView: TMyTEView);
  748.  
  749.     BEGIN
  750.         fTEView:= theTEView;
  751.     END;    {TMPWTextDocument.SetTEView}
  752.  
  753. {$S ARes}
  754. FUNCTION TMPWTextDocument.GetDesignDoc: TDesignDocument;
  755.  
  756.     BEGIN
  757.         GetDesignDoc:= fDesignDocument;
  758.     END;    {TMPWTextDocument.GetDesignDoc}
  759.  
  760. {$S ARes}
  761. PROCEDURE TMPWTextDocument.SetDesignDoc(theDesignDoc: TDesignDocument);
  762.  
  763.     BEGIN
  764.         fDesignDocument:= theDesignDoc;
  765.     END;    {TMPWTextDocument.SetDesignDoc}
  766.  
  767. {$S ARes}
  768. PROCEDURE TMPWTextDocument.SetTitleNoDialog(theName: str255);
  769.  
  770.     BEGIN
  771.         INHERITED SetTitle(theName);
  772.     END;    {TMPWTextDocument.SetTitleNoDialog}
  773.  
  774. {$S ARes}
  775. PROCEDURE TMPWTextDocument.SetTitle(aTitle: str255); OVERRIDE;
  776.  
  777.     BEGIN
  778.         INHERITED SetTitle(aTitle);
  779.     END;   {TMPWTextDocument.SetTitle}
  780.  
  781. {$S AOpen}
  782. PROCEDURE TMPWTextDocument.IMPWTextDocument(theDesignDoc: TDesignDocument; theName: str255);
  783.  
  784.     BEGIN
  785.         SELF.SetDocText(NIL);
  786.         SELF.IDocument(kMPWFileType, kMPWSignature, kUsesDataFork, kUsesRsrcFork, 
  787.                                         NOT kDataOpen, NOT kRsrcOpen);
  788.         SELF.SetTitleNoDialog(theName);
  789.         SELF.SetTEView(NIL);
  790.         SELF.SetDesignDoc(theDesignDoc);
  791.     END;    {TMPWTextDocument.IMPWTextDocument}
  792.  
  793.  
  794. {$S AOpen}
  795. PROCEDURE TMPWTextDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
  796.  
  797.     VAR
  798.         aView: TView;
  799.         aHandler: TStdPrintHandler;
  800.         aTEView: TMyTEView;
  801.  
  802.     BEGIN
  803.         aView := NewTemplateWindow(kMPWTEViewID, SELF);
  804.         FailNIL(aView);
  805.         aTEView := TMyTEView(aView.FindSubView(kMPWTEViewIdentifier));
  806.         SELF.SetTEView(aTEView);
  807.         TWindow(aView).Open;
  808.         New(aHandler);
  809.         FailNIL(aHandler);
  810.         aHandler.IStdPrintHandler(SELF, aTEView, NOT kSquareDots, kFixedSize, NOT kFixedSize);
  811.         aHandler.InstallMargins(gZeroRect, kUseMinimalMargins);
  812.     END;    {TMPWTextDocument.DoMakeViews}
  813.  
  814. {$S AClose}
  815. PROCEDURE TMPWTextDocument.FreeData; OVERRIDE;
  816.  
  817.     BEGIN
  818.         SetHandleSize(fDocText, 0);
  819.     END;    {TMPWTextDocument.FreeData}
  820.  
  821. {$S AClose}
  822. PROCEDURE TMPWTextDocument.Free; OVERRIDE;
  823.  
  824.     BEGIN
  825.         IF fDocText <> NIL THEN
  826.             DisPosHandle(fDocText);
  827.         INHERITED Free;
  828.     END;    {TMPWTextDocument.Free}
  829.  
  830. {$S AWriteFile}
  831. PROCEDURE TMPWTextDocument.DoNeedDiskSpace(VAR dataForkBytes, rsrcForkBytes: LongInt); 
  832.         OVERRIDE;
  833.  
  834.     BEGIN
  835.         dataForkBytes:= dataForkBytes + GetHandleSize(fDocText);
  836.         rsrcForkBytes:= rsrcForkBytes + kPrintInfoSize + kRsrcTypeOverhead + kRsrcOverhead;
  837.         INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
  838.     END;    {TMPWTextDocument.DoNeedDiskSpace}
  839.  
  840. {$S AWriteFile}
  841. PROCEDURE TMPWTextDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
  842.  
  843.     VAR
  844.         numChars: LONGINT;
  845.         tempHandle: Handle;
  846.  
  847.     BEGIN
  848.         numChars := GetHandleSize(fDocText);
  849.         FailOSErr(FSWrite(aRefNum, numChars, fDocText^));
  850.         IF fPrintInfo <> NIL THEN                            { Make sure we have one of these guys}
  851.             BEGIN
  852.                 tempHandle := fPrintInfo;
  853.                 FailOSErr(HandToHand(tempHandle));
  854.                 AddResource(tempHandle, kPrintInfoRsrcType, kPrintInfoRsrcID, '');
  855.                 FailResError;
  856.             END;
  857.     END;    {TMPWTextDocument.DoWrite}
  858.  
  859. {$S AFields}
  860. PROCEDURE TMPWTextDocument.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr; 
  861.         fieldType: INTEGER)); OVERRIDE;
  862.  
  863.     BEGIN
  864.         DoToField('TMPWTextDocument', NIL, bClass);
  865.         DoToField('fDocText', @fDocText, bHandle);
  866.         DoToField('fTEView', @fTEView, bObject);
  867.         DoToField('fDesignDocument', @fDesignDocument, bObject);
  868.         INHERITED Fields(DoToField);
  869.     END;    {TMPWTextDocument.Fields}
  870.  
  871.  
  872. (*************************************)
  873. (* methods for TMPWInterfaceDocument *)
  874. (*************************************)
  875. {$S AOpen}
  876. PROCEDURE TMPWInterfaceDocument.IMPWInterfaceDocument(theDesignDoc: TDesignDocument; 
  877.         theTextHandler: TTextHandler; theName: str255);
  878.         
  879.     BEGIN
  880.         SELF.IMPWTextDocument(theDesignDoc,theTextHandler.GetInterfaceFileName(theName));
  881.     END;    {TMPWInterfaceDocument.IMPWInterfaceDocument}
  882.     
  883. {$S AClose}
  884. PROCEDURE TMPWInterfaceDocument.Close;    OVERRIDE;
  885.     
  886.     BEGIN
  887.         IF fDesignDocument <> NIL THEN
  888.             fDesignDocument.SetMPWCodeView(NIL);
  889.         INHERITED Close;
  890.     END;    {TMPWInterfaceDocument.Close}
  891.  
  892.  
  893. (******************************************)
  894. (* methods for TMPWImplementationDocument *)
  895. (******************************************)
  896.  
  897. {$S AOpen}
  898. PROCEDURE TMPWImplementationDocument.IMPWImplementationDocument
  899.         (theDesignDoc: TDesignDocument; theTextHandler: TTextHandler; theName: str255);
  900.  
  901.     BEGIN
  902.         SELF.IMPWTextDocument(theDesignDoc,theTextHandler.GetImplementationFileName(theName));
  903.     END;    {TMPWImplementationDocument.IMPWImplementationDocument}
  904.     
  905. {$S AClose}
  906. PROCEDURE TMPWImplementationDocument.Close;    OVERRIDE;
  907.     
  908.     VAR
  909.         theTTEView: TMyTEView;
  910.         theDesignDoc: TDesignDocument;
  911.     
  912.     BEGIN
  913.         theTTEView:= fTEView;
  914.         theDesignDoc:= theTTEView.GetDesignDoc;
  915.         INHERITED Close;
  916.         IF theDesignDoc <> NIL THEN
  917.             theDesignDoc.SetMPWIncCodeView(NIL);
  918.     END;    {TMPWInterfaceDocument.Close}
  919.